//
//  MCGoodsCategoryCell.swift
//  StoreManage
//
//  Created by MC on 2018/9/11.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCGoodsCategoryCell: UITableViewCell {

    
    
    var isEditingStatus = false {
        didSet {
            editImageView.isHidden = isEditingStatus
        }
    }
    
    var model = MCGoodsCategoryModel() {
        didSet {
            nameLabel.text = model.name
            numberLabel.text = "（" + model.goodsNum.stringValue + "）"
        }
    }
    
    
    
    public class func customCell(tableView:UITableView) -> MCGoodsCategoryCell {
        
        let reuseIdentifier = "MCGoodsCategoryCell";
        var cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier)
        
        cell = MCGoodsCategoryCell(style: .default, reuseIdentifier: reuseIdentifier)
        

        
        return cell as! MCGoodsCategoryCell
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = UITableViewCellSelectionStyle.none

        backgroundColor = UIColor.white
        
        self.addSubview(lineView)
        self.addSubview(nameLabel)
        self.addSubview(numberLabel)
        self.addSubview(editImageView)

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(1)
        }
        
        nameLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.centerY.equalTo(self)
        }
        
        numberLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(nameLabel.snp.right).offset(3)
            make.centerY.equalTo(self)
        }

        
        editImageView.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-15)
            make.centerY.equalTo(self)
            make.size.equalTo(CGSize.init(width: 15, height: 15))
        }

    }
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()

    lazy var nameLabel: MCLabel = {
        let label = MCLabel()
        label.font = MCFont(15)
        label.text = "XXX"
        return label
    }()
    
    lazy var numberLabel: MCLabel = {
        let label = MCLabel()
        label.font = MCFont(13)
        label.textColor = UIColor.MCGray_middle
        label.text = "（0）"
        return label
    }()
    
    lazy var editImageView: UIImageView = {
        let iv = UIImageView()
        iv.image = #imageLiteral(resourceName: "GoodsManage_edit").MCImageWithTintColor(color: UIColor.MCGray_middle)
        return iv
    }()

}
